package org.jawa.exam.model;

import java.util.Date;

import org.jawa.core.cache.Cache;
import org.jawa.core.cache.CacheFactory;
import org.jawa.core.cache.CacheSizes;
import org.jawa.core.cache.Cacheable;
import org.jawa.core.cache.CannotCalculateSizeException;
import org.jawa.core.exception.NotFoundException;
import org.jawa.core.util.DateConvertUtils;
import org.jawa.jdbc.Lazyable;

/**
 * 
 * 类文件: Question
 * <p>
 * <p>
 * 类描述：试题信息表
 * <p>
 * 作     者： migrant423
 * <p>
 * 日     期： 2012-7-16
 * <p>
 * 时     间： 下午9:22:45
 * <p>
 */
public class Question implements Cacheable, Lazyable {

	private static final long serialVersionUID = 7451332800927469472L;

	protected static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
	
	/**
	 * 试题编号
	 * @return 
	 */
	private Long questionId;
	/**
	 * 业务类型
	 */
	private String questionKind;
	/**
	 * 试题类型
	 */
	private String questionType;
	/**
	 * 试题难度
	 */
	private String difficulty;
	/**
	 * 试题内容
	 */
	private String questionContent;
	/**
	 * 试题答案
	 */
	private String questionAnswer;
	/**
	 * 试题分值
	 */
	private Double questionScore;
	/**
	 * 答题限时
	 */
	private Long timeOut;
	/**
	 * 试题解析
	 */
	private String questionDesc;
	/**
	 * 试题发布人
	 */
	private Long postUser;
	/**
	 * 试题发布时间
	 */
	private Date postTime;
	/**
	 * 试题状态
	 */
	private String questionStatus;
	/**
	 * 试题被选次数
	 */
	private Long choiceNum;
	/**
	 * 回答正确次数
	 */
	private Long rightNum;
	/**
	 * 回答错误次数
	 */
	private Long errorNum;
	/**
	 * 备注
	 */
	private String remark;

	public Long getQuestionId() {
		return questionId;
	}

	public void setQuestionId(Long questionId) {
		this.questionId = questionId;
	}

	public String getQuestionKind() {
		return questionKind;
	}

	public void setQuestionKind(String questionKind) {
		this.questionKind = questionKind;
	}

	public String getQuestionType() {
		return questionType;
	}

	public void setQuestionType(String questionType) {
		this.questionType = questionType;
	}

	public String getDifficulty() {
		return difficulty;
	}

	public void setDifficulty(String difficulty) {
		this.difficulty = difficulty;
	}

	public String getQuestionContent() {
		return questionContent;
	}

	public void setQuestionContent(String questionContent) {
		this.questionContent = questionContent;
	}

	public String getQuestionAnswer() {
		return questionAnswer;
	}

	public void setQuestionAnswer(String questionAnswer) {
		this.questionAnswer = questionAnswer;
	}

	public Double getQuestionScore() {
		return questionScore;
	}

	public void setQuestionScore(double questionScore) {
		this.questionScore = questionScore;
	}

	public Long getTimeOut() {
		return timeOut;
	}

	public void setTimeOut(Long timeOut) {
		this.timeOut = timeOut;
	}

	public String getQuestionDesc() {
		return questionDesc;
	}

	public void setQuestionDesc(String questionDesc) {
		this.questionDesc = questionDesc;
	}

	public Long getPostUser() {
		return postUser;
	}

	public void setPostUser(Long postUser) {
		this.postUser = postUser;
	}

	public Date getPostTime() {
		return postTime;
	}

	public void setPostTime(Date postTime) {
		this.postTime = postTime;
	}

	public String getPostTimeString() {
		return date2String(getPostTime(), DATE_TIME_FORMAT);
	}

	public void setPostTimeString(String value) {
		setPostTime(string2Date(value, DATE_TIME_FORMAT, java.util.Date.class));
	}

	public String getQuestionStatus() {
		return questionStatus;
	}

	public void setQuestionStatus(String questionStatus) {
		this.questionStatus = questionStatus;
	}

	public Long getChoiceNum() {
		return choiceNum;
	}

	public void setChoiceNum(Long choiceNum) {
		this.choiceNum = choiceNum;
	}

	public Long getRightNum() {
		return rightNum;
	}

	public void setRightNum(Long rightNum) {
		this.rightNum = rightNum;
	}

	public Long getErrorNum() {
		return errorNum;
	}

	public void setErrorNum(Long errorNum) {
		this.errorNum = errorNum;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	/**
	 * 用于将日期转为指定格式的字符串
	 * @param date 需要转换的日期(java.util.Date实例)
	 * @param dateFormat 指定的格式，如：yyyy-MM-dd HH:mm:ss
	 * @return 转换后的字符串
	 */
	private static String date2String(java.util.Date date, String dateFormat) {
		return DateConvertUtils.format(date, dateFormat);
	} 

	/**
	 * 将字符串转换为日期
	 * @param dateString 必需是与yyyy-MM-dd HH:mm:ss相似的字符串
	 * @param dateFormat 日期格式
	 * @param targetResultType 返回的类型默认为：java.util.Date
	 * @return 返回格式后的日期实例
	 */
	private static <T extends java.util.Date> T string2Date(String dateString, String dateFormat,
			Class<T> targetResultType) {
		return DateConvertUtils.parse(dateString, dateFormat, targetResultType);
	}

	/**
	 * 返回估算的对象在缓存中的占用大小
	* <p>Title: getCachedSize</p>
	* <p>Description: </p>
	* @return
	* @throws CannotCalculateSizeException
	* @see org.jawa.core.cache.Cacheable#getCachedSize()
	 */
	public int getCachedSize() throws CannotCalculateSizeException {
		int size = 0;
		size += CacheSizes.sizeOfObject();
		size += CacheSizes.sizeOfLong();
		size += CacheSizes.sizeOfString(questionKind);
		size += CacheSizes.sizeOfString(questionType);
		size += CacheSizes.sizeOfString(difficulty);
		size += CacheSizes.sizeOfString(questionContent);
		size += CacheSizes.sizeOfString(questionAnswer);
		size += CacheSizes.sizeOfDouble();
		size += CacheSizes.sizeOfLong();
		size += CacheSizes.sizeOfString(questionDesc);
		size += CacheSizes.sizeOfLong();
		size += CacheSizes.sizeOfDate();

		size += CacheSizes.sizeOfString(questionStatus);
		size += CacheSizes.sizeOfLong();
		size += CacheSizes.sizeOfLong();
		size += CacheSizes.sizeOfLong();
		size += CacheSizes.sizeOfString(remark);
		return size;
	}

	@Override
	public void load() throws NotFoundException {

	}

}
